<template>
<div>
  <el-form ref="form" v-model="form"  label-width="80px">
    <el-form-item label="地址解析">
      <el-cascader
        v-model="option"
        :options="addressList"
        :props="{'value':'label','label':'value'}"
        clearable></el-cascader>
    </el-form-item>
    <el-form-item label="地址解析">
      <el-input v-model="form.address"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="addAddress">添加</el-button>
      <el-button type="primary" @click="getAddressShow">回显</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import {getAddress, getAddressList} from "@/api/cascader";

export default {
  name: "cascader",
  data(){
    return {
      addressList: [],
      option: [],
      address: [],
      form: {
        address: "",
      },
      num: []
    }
  },
  created() {
    this.showAddressList()
  },
  methods: {
    showAddressList(){
      getAddressList().then(res => {
        this.addressList = res.data
      })
    },
    addAddress(){
      console.log(this.option)
    },
    getAddressShow(){
      this.address = this.form.address.split(',')
      this.option = this.address
      // getAddress(this.address).then(res => {
      //   this.num = res.data
      //   console.log(this.num)
      //   this.option = this.num[this.num.length-1]
      //   console.log(this.option)
      // })
    }

  }
}
</script>

<style scoped>

</style>
